<template>
  <div>
      <van-field label="用户名" placeholder="请输入用户名" v-model="form.name"/>
      <van-field label="密码" placeholder="请输入密码" v-model="form.password"/>
      <van-button @click="login"> 登陆 </van-button>
  </div>
</template>
<script>
import axios from 'axios'

export default {
    data(){
        return{
            form:{'name':'','password':''}
        }
    },
    methods:{
        login(){
            axios.post('http://127.0.0.1:5000/flogin',this.form).then(res=>{
                console.log(res);
                if(res.data.code == 200){
                    this.$toast.success("登陆成功")
                    localStorage.setItem('uid',res.data.userid)
                    localStorage.setItem('uname',res.data.name)
                    localStorage.setItem('resourcelist',JSON.stringify(res.data.reslist))
                    this.$router.push('menu')                
                }else{
                    this.$toast.fail("登陆失败")
                }

            })
        }
    },
}
</script>
<style>
</style>